﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Entity;
using School.Entities;
using School.Common;
using School.Accounting;

namespace School.Bus.Accounting
{
    public partial class VoucherPayment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            long payment_number = 0;

            if (long.TryParse(Request.QueryString["Number"], out payment_number))
            {
                if (Request.QueryString["Print"] != "1")
                {
                    var p = Voucher.GetPaymentOrdersByNumber(payment_number);

                    if (p.Count() > 0)
                    {
                        decimal paid = 0;

                        DateTime voucherDate = DateTime.Now;

                        DateTime.TryParse(Request.QueryString["date"], out voucherDate);

                        decimal.TryParse(Request.QueryString["Paid"], out paid);                        

                        long v = Voucher.AddVoucherFromPaymentOrder(p.First(),paid,voucherDate);

                        var ri = Voucher.GetVoucherReport(v);

                        //LblStudentName.Text = ri.Student_Name;
                        //LblCampusName.Text = ri.Campus_Name;
                        //LblCertificateName.Text = ri.Certitificate_Name;
                        //LblStageName.Text = ri.Stage_Name;
                        //LblGradeName.Text = ri.Grade_Name;
                        //LblPrice.Text = ri.Value.ToString();
                        //LblExpenseName.Text = ri.Expense_Name;
                        //LblVoucherNumber.Text = ri.Voucher_Number.ToString();
                        //LblDate.Text = ri.Date;

                        //GridView1.DataSource = Voucher.GetDiscounts(v);
                        //GridView1.DataBind();

                        Response.Redirect("VoucherPayment.aspx?Number=" + v.ToString() + "&Print=1");
                    }
                }
                else
                {
                }
            }
        }

        protected string GetValue(object type, object value)
        {
            return type.ToString() == "1" ? value.ToString() + " جنيه" : value.ToString() + "%";
        }
    }
}